package org.example.struct.array;

import java.util.ArrayList;
import java.util.List;

/**
 * @author liyishan
 * @date 2024/6/18 11:24
 * @apiNote
 */

public class Test00821ShortestToChar {

    public int[] shortestToChar(String s, char c) {
        List<Integer> sizeList = new ArrayList<>();
        char[] arr = s.toCharArray();
        for(int i = 0; i < arr.length; i++){
            if(arr[i] == c){
                sizeList.add(i);
            }
        }
        int[] answer = new int[arr.length];
        for(int i = 0; i < arr.length; i++){
            int size = Integer.MAX_VALUE;
            for(int j = 0;j<sizeList.size();j++){
                int abs = Math.abs(i - sizeList.get(j));
                size = Math.min(size,abs);
            }
            answer[i] = size;
        }
        return answer;
    }
}
